package com.example.webproject.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Data;
import lombok.ToString;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author hhs
 * @Description
 * @date 2022/12/6 13:36
 */

@Data
@Table(name = "t_cause")
@Entity
public class Course{
    @Id
    @GeneratedValue
    private Long id;
    /**
     * 课程名称
     */
    private String name;
    /**
     * 课程描述
     */
    private String description;
    private String cover;
    /**
     * 多门课程对应一个老师
     */
//    @JsonBackReference
    @ToString.Exclude
    @ManyToOne(cascade = {CascadeType.MERGE,CascadeType.REFRESH})
    private User teacher;
    /**
     * 创建时间
     */
    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime;
    @Temporal(TemporalType.TIMESTAMP)
    /**
     * 更新时间
     */
    private Date updateTime;

    private boolean isOpen;
    /**
     * 多个课程对应多个学生
     * 一个课程可以有多个学生
     */
//    @JsonIgnore
    @ManyToMany
    private List<User> students=new ArrayList<>();
//    @JsonManagedReference
//    @OneToMany(mappedBy="course")
//    private List<Chapter> chapters=new ArrayList<>();
//
//    @OneToMany(mappedBy = "course")
//    private List<Applicant> applicant=new ArrayList<>();


//    @JsonIgnore
//    public List<User> getStudents() {
//        return students;
//    }
    @JsonBackReference
    public User getTeacher() {
        return teacher;
    }
//    @JsonBackReference
//    public List<Chapter> getChapters() {
//        return chapters;
//    }
//    @JsonBackReference
//
//    public List<Applicant> getApplicant() {
//        return applicant;
//    }
}
